﻿//科室管理的全局变量
var shangpinrkd = {
	databaseTime: {"kaishisj":'',"jeishusj":''},
	url: {
	getShangpinrkdlbURL: function () {
			return path + '/shangpinrkd/getShangpinrkdList';
		},
		getShangpinrkdCountURL: function () {
			return path + '/shangpinrkd/getShangpinrkdCount';
		},gongyingshanglbURL: function () {
			return path + '/shangpinrkd/getGongyingshangList';
		}
	},
	
	getListParams: function () {
		var rukuzt = $('#rukudzt').val();
		var kaishisj=$('#rugl-kaishjsj').val();
		var jieshusj=$('#rugl-jieshusj').val();
		var gongyingsid=$('#gongyingsid').val();
		var params = {
			"rukudzt": rukuzt,
			"kaishisj":kaishisj,
			"jieshusj":jieshusj,
			"gongyingsid":gongyingsid
		}
		return params;
	},
	
	init: function(firstDate,secondDate){
		shangpinrkd.databaseTime =common_util.dateTimePicker(firstDate,secondDate);
		shangpinrkd.bandFunction();
		shangpinrkd.getGongyingshang();
		shangpinrkd.fenye();
	},
	
	getinsertMsg: function(){
		
	},
	getmsg: function(){
		
	},
	find: function(){
		
	},
	
	//绑定的方法
	bandFunction: function(){
		var A = 0;
		$("#dhyaopin").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".nav-comsumer-goods").click(function(){
			if(A>0){
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		        	window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".shangpinrk").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".yaopin-pici").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".haocai-pici").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".kuc").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		$(".rukugl").click(function(){
			if(A>0){
				//confirm("编辑内容没有保存，是否离开？");
				if(confirm("编辑内容没有保存，是否离开？")){
					A = 0;
					$(".g-left-nav li span").css("border","none");
		            $(this).css("border","solid 1px #00b472");
		            $("#cedan").html();
		            window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
					return false;
				}else{
					return false;
				};
			};
			$(".g-left-nav li span").css("border","none");
	        $(this).css("border","solid 1px #00b472");
			$("#cedan").removeData();
			window.location.href = path+"/views/kucun/kucun.jsp?navMingChen="+$(this).text();
		});
		
		//回车事件绑定到查询按钮
		$(document).keydown(function(){ 
			if(event.keyCode==13){ 
			$("#rukugl-search").trigger('click'); 
			return false;
			}
		});
		
		// 新建页面跳转
		$(document).on('click','#rukugl-dengji',function(){
			window.location.href = path+"rukugl-dengji.jsp";
		});
		
		// 详情事件
		$(document).on('click', '.caozuo1', function () {
			var shangpinrkdid = $(this).parent().attr('id');
			window.location.href = path + '/views/kucun/rukugl/rukugl-detail.jsp?shangpinrkdid='+shangpinrkdid;
		});
		
		// 绿色单选按钮
		$(document).on('click','#rukuztul li', function () {
			$('#rukudzt').val($(this).attr('value'));
			$(this).siblings('li').removeClass('xuanzhong');
			$(this).addClass('xuanzhong');
			shangpinrkd.fenye();
		});
		
		// 状态下拉 
		$(document).on('click','#gongyingshangul li', function () {
			$('#gongyingsid').val($(this).attr('value'));
			$('#gongyingsdiv').text($(this).text()).css('color','#333');
			$(this).parent().css('display', 'none');
			shangpinrkd.fenye();
		});
		
		// 查询按钮点击
		$('#rukugl-search').on('click', function () {
			shangpinrkd.fenye();
		});
		
		// 重置按钮
		$('#rukugl-reset').on('click', function () {
			$('#gongyingsid').val('');
			$('#gongyingsdiv').text('请选择供应商名称').css('color','#999');
			$('#rugl-kaishjsj').val(shangpinrkd.databaseTime.kaishisj);
			$('#rugl-jieshusj').val(shangpinrkd.databaseTime.jieshusj);
			$('#rukuztul').children('li:eq(0)').trigger('click');
			shangpinrkd.fenye();
		});
	},
	fenye: function() {// 分页
		fenye.fenye(shangpinrkd.url.getShangpinrkdCountURL(), shangpinrkd.url.getShangpinrkdlbURL(),
				shangpinrkd.getListParams(), "pagination-shangpinrkd", "shangpinrkdtb");
	},xinjian:function(){//新建
		
	},
	getZdGongyingshang(){//检索字典供应商
		
	},
	convertZhuangtaiToCaozuo: function(value) {// 状态前后端转换
		var result = "";
		switch (value) {
			case 0:
				result = "禁用";
				break;
			case 1:
				result = "启用";
				break;
		}
		return result;
	},
	getGongyingshang: function(){
		$.ajax({
			url: shangpinrkd.url.gongyingshanglbURL(),
			type:'post',
			success:function(data) {
				var str = "";
				if(data != '') {
						str += '<li>全部</li>';
					$(data).each(function(){
						 str+='<li index="'+this.mingcheng+','+this.dizhi+'" value="' + this.id + '">'+this.mingcheng+'</li>';
					});
				} 
				$('#gongyingshangul').html("");
				$('#gongyingshangul').html(str);
			}
		});
	},
}